#!usr/bin/node

const http = require('http');
      

http.createServer((req,res) => {
  console.log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  console.log(req.headers.host);
  console.log(req.headers['user-agent']);
  console.log(req.headers['content-type']);

  //get username and password
  let auth = req.headers.authorization;
  auth = auth.split(' ')[1];
  auth = Buffer.from(auth,'base64');
  auth = auth.toString('utf8').split(':');

  console.log(`username:${auth[0]} password:${auth[1]}`);

  res.end("ok");
}).listen(8080);
